<?php

namespace App\Excels\Imports;

use Illuminate\Support\Carbon;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\WithMapping;

class RecordByHandleImporter implements ToArray, WithMapping
{

    public array $datas = [

    ];

    public function map($row): array
    {
        return $row;
    }

    public function array(array $array): void
    {
        if (empty($array)) return;
        array_shift($array);
        foreach ($array as $item){
            if(empty($item[0])) break;
            $date = trim($item[0]);
            if(is_numeric($date)){
                $date = Carbon::createFromFormat('Y-m-d', '1900-01-01')
                    ->addDays($date - 2)
                    ->format('Y-m-d');
            }
            $this->datas[] = [
                "date"=>$date,
                "income"=>trim($item[1]),
                "settle_money"=>trim($item[2]),
            ];
        }
    }
}
